package com.ruoyi.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manager.domain.Strategy;
import com.ruoyi.manager.service.IStrategyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * strategyController
 * 
 * @author ruoyi
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/manager/strategy")
public class StrategyController extends BaseController
{
    @Autowired
    private IStrategyService strategyService;

    /**
     * 查询strategy列表
     */
    @PreAuthorize("@ss.hasPermi('manager:strategy:list')")
    @GetMapping("/list")
    public TableDataInfo list(Strategy strategy)
    {
        startPage();
        List<Strategy> list = strategyService.selectStrategyList(strategy);
        return getDataTable(list);
    }

    /**
     * 导出strategy列表
     */
    @PreAuthorize("@ss.hasPermi('manager:strategy:export')")
    @Log(title = "strategy", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Strategy strategy)
    {
        List<Strategy> list = strategyService.selectStrategyList(strategy);
        ExcelUtil<Strategy> util = new ExcelUtil<Strategy>(Strategy.class);
        util.exportExcel(response, list, "strategy数据");
    }

    /**
     * 获取strategy详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:strategy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(strategyService.selectStrategyById(id));
    }

    /**
     * 新增strategy
     */
    @PreAuthorize("@ss.hasPermi('manager:strategy:add')")
    @Log(title = "strategy", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Strategy strategy)
    {
        return toAjax(strategyService.insertStrategy(strategy));
    }

    /**
     * 修改strategy
     */
    @PreAuthorize("@ss.hasPermi('manager:strategy:edit')")
    @Log(title = "strategy", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Strategy strategy)
    {
        return toAjax(strategyService.updateStrategy(strategy));
    }

    /**
     * 删除strategy
     */
    @PreAuthorize("@ss.hasPermi('manager:strategy:remove')")
    @Log(title = "strategy", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(strategyService.deleteStrategyByIds(ids));
    }
}
